package com.rainbow.mybatis;

import com.rainbow.beans.Test;
import com.rainbow.mapper.TestMapper;
import com.rainbow.mybatis.config.Configuration;
import com.rainbow.mybatis.executor.ExecutorFactory;
import com.rainbow.mybatis.mybatisinterceptor.TestMybatisInterceptor;
import com.rainbow.mybatis.mybatisinterceptor.TestTwoMybatisInterceptor;
import com.rainbow.mybatis.plugin.Interceptor;
import com.rainbow.mybatis.session.GpSqlSession;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by James on 2017-07-05.
 * From 咕泡学院出品
 * 老师咨询 QQ 2904270631
 */
public class BootStrap {
    public static void main(String[] args) throws IOException {
        start();
    }

    private static void start() throws IOException {
        Configuration configuration = new Configuration();
        configuration.setScanPath("com.rainbow.mapper");
        List<Interceptor> interceptors = new ArrayList<>();
        interceptors.add(new TestMybatisInterceptor());
        interceptors.add(new TestTwoMybatisInterceptor());
        configuration.build(interceptors);
        //GpSqlSession sqlSession = new GpSqlSession(configuration, ExecutorFactory.DEFAULT(configuration));
        GpSqlSession sqlSession = new GpSqlSession(configuration,
                ExecutorFactory.get(ExecutorFactory.ExecutorType.CACHING.name(),configuration));
        TestMapper testMapper = sqlSession.getMapper(TestMapper.class);
        long start = System.currentTimeMillis();
        Test test = testMapper.selectByPrimaryKey(3);
        System.out.println("cost:"+ (System.currentTimeMillis() -start));
        System.out.println(test.toString());
//        start = System.currentTimeMillis();
//        test = testMapper.selectByPrimaryKey(1);
//        System.out.println("cost:"+ (System.currentTimeMillis() -start));
//        System.out.println(test);
    }
}
